package com.mindtalk.screen;

import java.util.ArrayList;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;

import com.mindtalk.R;
import com.mindtalk.helper.ConferenceAdapter;
import com.mindtalk.screen.dialog.RoomSettings;
import com.mindtalk.transferdata.MyChannelsData;

public class Conferences extends ListActivity implements OnClickListener,OnItemClickListener{
	
/* Daftar Variable */
	
	/**
	 *  List Nama Conferences yang Dimiliki oleh User Sekarang
	 *  */
	private ArrayList<MyChannelsData> channels = new ArrayList<MyChannelsData>();
	
	/**
	 * Adapter
	 * */
	ConferenceAdapter adapter;
	/**
	 * Handler untuk Show Dialog
	 * */
	Handler mHandler = new Handler();
	/**
	 * Dialog Activity
	 * */
	RoomSettings dialogRoomSettings;
	
	/**
	 * Function List
	 * */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.conferencesreallayout);
		ListView list = (ListView)findViewById(android.R.id.list);
		list.setOnItemClickListener(this);
		adapter = new ConferenceAdapter(this, channels, R.layout.conferences, getLayoutInflater());			
		setListAdapter(adapter);			
		Button createRoom = (Button)findViewById(R.id.btn_conference_createroom);
		createRoom.setOnClickListener(this);
		dialogRoomSettings = new RoomSettings(this);
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.getId() == R.id.btn_conference_createroom){
			
			/**
			 * Show Dialog Buat Setting Create Room
			 * */					
			mHandler.post(new Runnable() {
				
				@Override
				public void run() {
					// TODO Auto-generated method stub
					dialogRoomSettings.show();					
				}
			});
			
			
		}
	}
	
	/**
	 * Menambahkan Data Ke Dalam list
	 * */
	public void addAdapter(MyChannelsData data){
		adapter.add(data);		
	}
	
	@Override
	public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
		// TODO Auto-generated method stub
		MyChannelsData data = (MyChannelsData) adapter.getItemAtPosition(position);	
		if(data!=null){
			Intent intent = new Intent(view.getContext(), ConferenceDetail.class);	
			intent.putExtra("information",data.roomName);
			startActivity(intent);
		}
	}	
}
